﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LdCms.BLL.Community
{
    using LdCms.EF.DbEntitiesContext;
    using LdCms.EF.DbModels;
    using LdCms.EF.DbStoredProcedure;
    using LdCms.IBLL.Community;
    using LdCms.IDAL.Community;
    using LdCms.Common.Json;
    using LdCms.Common.Security;
    using LdCms.Common.Extension;
    public partial class ConfigService:BaseService<Ld_Community_Config>,IConfigService
    {
        private readonly IConfigDAL ConfigDAL;
        private readonly LdCmsDbEntitiesContext LdCmsDbEntitiesContext;
        public ConfigService(LdCmsDbEntitiesContext LdCmsDbEntitiesContext, IConfigDAL ConfigDAL)
        {
            this.LdCmsDbEntitiesContext = LdCmsDbEntitiesContext;
            this.ConfigDAL = ConfigDAL;
            this.Dal = ConfigDAL;
        }
        public override void SetDal()
        {
            Dal = ConfigDAL;
        }

        public bool IsExists(int systemId, string companyId)
        {
            try
            {
                return IsExists(m => m.SystemID == systemId && m.CompanyID == companyId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public bool UpdateConfig(Ld_Community_Config entity)
        {
            try
            {
                int systemId = entity.SystemID;
                string companyId = entity.CompanyID;
                if (!IsExists(systemId, companyId))
                    throw new Exception("ID无效！");
                return Update(entity);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public Ld_Community_Config GetConfig(int systemId, string companyId)
        {
            try
            {
                return Find(m => m.SystemID == systemId && m.CompanyID == companyId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


    }
}
